package com.zlzxm.sorting.util

import android.content.Context
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.luck.picture.lib.engine.ImageEngine
import com.luck.picture.lib.utils.ActivityCompatHelper
import com.zlzxm.sorting.R


/**
 *
 *CREATE BY zlzxm ON 2022/7/7
 *
 */
object GlideEngine : ImageEngine {

    override fun loadImage(context: Context?, url: String?, imageView: ImageView?) {

        Glide.with(context!!)
            .load(url)
            .into(imageView!!)
    }

    override fun loadImage(
        context: Context?,
        imageView: ImageView?,
        url: String?,
        maxWidth: Int,
        maxHeight: Int
    ) {
        Glide.with(context!!)
            .load(url)
            .override(maxWidth,maxHeight)
            .into(imageView!!)
    }

    override fun loadAlbumCover(context: Context?, url: String?, imageView: ImageView?) {

        Glide.with(context!!)
            .asBitmap()
            .load(url)
            .override(180, 180)
            .sizeMultiplier(0.5f)
            .transform(CenterCrop(), RoundedCorners(8))
            .placeholder(R.mipmap.ic_launcher)
            .into(imageView!!)
    }

    override fun loadGridImage(context: Context?, url: String?, imageView: ImageView?) {

        if (!ActivityCompatHelper.assertValidRequest(context)) {
            return;
        }
        Glide.with(context!!)
            .load(url)
            .override(200, 200)
            .centerCrop()
            .placeholder(R.mipmap.ic_launcher)
            .into(imageView!!)
    }

    override fun pauseRequests(context: Context?) {
        Glide.with(context!!).pauseRequests();
    }

    override fun resumeRequests(context: Context?) {
        Glide.with(context!!).resumeRequests();
    }
}